package com.corner.presenter.imp;

import android.text.TextUtils;

import com.corner.app.App;
import com.corner.app.GlobalParams;
import com.corner.model.db.Session;
import com.corner.presenter.IChatAudioPresenter;
import com.corner.presenter.base.BasePresenter;
import com.corner.utils.DownLoadUtil;

import java.io.File;

/**
 * Created by Administrator on 2015/7/14，14.33.
 * 描述：
 */
public class ChatAudioPresenter extends BasePresenter implements IChatAudioPresenter {
    @Override
    public void downAudio(final Session session) {
        if (!TextUtils.isEmpty(session.getAudioPath()) && !new File(session.getAudioPath()).exists() || TextUtils.isEmpty(session.getAudioPath())) {
            if (!TextUtils.isEmpty(session.getAudio())) {
                String path = GlobalParams.APPFIEPATH + "/audio/" + session.getAudio().hashCode() + ".amr";
                DownLoadUtil.getInstance().getFilePath(path, session.getAudio(), new DownLoadUtil.GetFileCallBack() {
                    @Override
                    public void onFinish(String filePath) {
                        session.setAudioPath(filePath);
                        App.application.daoSession.getSessionDao().update(session);
                    }
                });
            }
        }
    }
}
